2020-2021 Sunseeker Telemetry and Lighting System
eusci_a_spi_ex1_slave.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //*****************************************************************************
70 //
71 //*****************************************************************************
72 
73 #include "driverlib.h"
74 
75 uint8_t transmitData = 0x01, receiveData = 0x00;
76 
77 void main(void)
78 {
79  //Stop watchdog timer
80  WDT_A_hold(WDT_A_BASE);
81 
82  // Configure Pins for LFXIN
83  //Set PJ.4 and PJ.5 as Primary Module Function Input.
84  /*
85 
86  * Select Port J
87  * Set Pin 4, 5 to input Primary Module Function, (LFXIN).
88  */
89  GPIO_setAsPeripheralModuleFunctionInputPin(
90  GPIO_PORT_PJ,
91  GPIO_PIN4 + GPIO_PIN5,
92  GPIO_PRIMARY_MODULE_FUNCTION
93  );
94 
95  // Configure SPI pins
96  // Configure Pins for UCA0CLK
97  //Set P1.5 as Secondary Module Function Input.
98  /*
99 
100  * Select Port 1
101  * Set Pin 5 to input Secondary Module Function, (UCA0CLK).
102  */
103  GPIO_setAsPeripheralModuleFunctionInputPin(
104  GPIO_PORT_P1,
105  GPIO_PIN5,
106  GPIO_SECONDARY_MODULE_FUNCTION
107  );
108  // Configure Pins for UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI
109  //Set P2.0, P2.1 as Secondary Module Function Input.
110  /*
111 
112  * Select Port 2
113  * Set Pin 0, 1 to input Secondary Module Function, (UCA0TXD/UCA0SIMO, UCA0RXD/UCA0SOMI).
114  */
115  GPIO_setAsPeripheralModuleFunctionInputPin(
116  GPIO_PORT_P2,
117  GPIO_PIN0 + GPIO_PIN1,
118  GPIO_SECONDARY_MODULE_FUNCTION
119  );
120 
121  /*
122  * Disable the GPIO power-on default high-impedance mode to activate
123  * previously configured port settings
124  */
125  PMM_unlockLPM5();
126 
127  //Initialize slave to MSB first, inactive high clock polarity and 3 wire SPI
128  EUSCI_A_SPI_initSlaveParam param = {0};
129  param.msbFirst = EUSCI_A_SPI_MSB_FIRST;
130  param.clockPhase = EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
131  param.clockPolarity = EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH;
132  param.spiMode = EUSCI_A_SPI_3PIN;
133  EUSCI_A_SPI_initSlave(EUSCI_A0_BASE, &param);
134 
135  //Enable SPI Module
136  EUSCI_A_SPI_enable(EUSCI_A0_BASE);
137 
138  EUSCI_A_SPI_clearInterrupt(EUSCI_A0_BASE,
139  EUSCI_A_SPI_RECEIVE_INTERRUPT);
140 
141  //Enable Receive interrupt
142  EUSCI_A_SPI_enableInterrupt(EUSCI_A0_BASE,
143  EUSCI_A_SPI_RECEIVE_INTERRUPT
144  );
145 
146  __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
147 }
148 
149 //******************************************************************************
150 //
151 //This is the USCI_A0 interrupt vector service routine.
152 //
153 //******************************************************************************
154 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
155 #pragma vector=USCI_A0_VECTOR
156 __interrupt
157 #elif defined(__GNUC__)
158 __attribute__((interrupt(USCI_A0_VECTOR)))
159 #endif
160 void USCI_A0_ISR (void)
161 {
162  switch(__even_in_range(UCA0IV, USCI_SPI_UCTXIFG))
163  {
164  case USCI_SPI_UCRXIFG: // UCRXIFG
165  //USCI_A0 TX buffer ready?
166  while (!EUSCI_A_SPI_getInterruptStatus(EUSCI_A0_BASE,
167  EUSCI_A_SPI_TRANSMIT_INTERRUPT
168  ));
169 
170  //Transmit data to master
171  EUSCI_A_SPI_transmitData(EUSCI_A0_BASE,
173  );
174 
175  //Receive data from master
176  receiveData = EUSCI_A_SPI_receiveData(EUSCI_A0_BASE);
177 
178  //Increment data to be transmitted
179  transmitData++;
180  break;
181  default:
182  break;
183  }
184 }
185 
uint8_t receiveData
void main(void)
void USCI_A0_ISR(void)
uint8_t transmitData
MPU_initThreeSegmentsParam param